import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SolutionLCP63 {

    int[] dx = {1, 0, -1, 0};
    int[] dy = {0, 1, 0, -1};
    int num;

    public int[][] ballGame(int num, String[] plate) {
        this.num=num;
        if (plate.length==1 || plate[0].length()==1){
            return new int[][]{};
        }
        List<int[]> ans=new ArrayList<>();
        for (int i=1;i<plate[0].length()-1;i++){
            if (check(plate,0,0,i)){
                ans.add(new int[]{0,i});
            }
        }
        for (int i=1;i<plate[0].length()-1;i++){
            if (check(plate,2,plate.length-1,i)){
                ans.add(new int[]{plate.length-1,i});
            }
        }
        for (int i=1;i<plate.length-1;i++){
            if (check(plate,1,i,0)){
                ans.add(new int[]{i,0});
            }
        }
        for (int i=1;i<plate.length-1;i++){
            if (check(plate,3,i,plate[0].length()-1)){
                ans.add(new int[]{i,plate[0].length()-1});
            }
        }
        int[][] a = new int[ans.size()][2];
        int count = 0;
        for (int[] an : ans) {
            a[count++]=an;
        }
        return a;
    }

    private boolean check(String[] plate, int dir, int x, int y) {
        if (plate[x].charAt(y)!='.'){
            return false;
        }
        for (int i = 0; i < num; i++) {
            x+=dx[dir];
            y+=dy[dir];
            if (x<0 || x>=plate.length || y<0 || y>=plate[0].length()){
                return false;
            }
            if (plate[x].charAt(y)=='O'){
                return true;
            }
            if (plate[x].charAt(y)=='E'){
                dir=(dir+3)%4;
            }else if (plate[x].charAt(y)=='W'){
                dir=(dir+1)%4;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(new SolutionLCP63().ballGame(4, new String[]{"..E.", ".EOW", "..W."})));
    }
}
